package com.wchen.gdoc.generate.resource.analysis;

import com.sun.javadoc.FieldDoc;

import java.util.HashSet;
import java.util.Set;

/**
 * 字段类型过滤器
 *
 * @author  wchen
 * @date    2019/11/7
 */
public class FieldTypeFilter {
    private static Set<String> paramSkipSet = new HashSet<>();
    private static Set<String> returnedSkipSet = new HashSet<>();
    public FieldTypeFilter() {
        synchronized(FieldTypeFilter.class) {
            if (paramSkipSet.isEmpty() || returnedSkipSet.isEmpty()) {
                paramSkipSet.add("gmtCreate");
                paramSkipSet.add("serialVersionUID");
                paramSkipSet.add("gmtModified");
                paramSkipSet.add("ITree");
                paramSkipSet.add("id");
                paramSkipSet.add("isDelete");
                paramSkipSet.add("java.lang.Class");

                returnedSkipSet.add("gmtModified");
                returnedSkipSet.add("serialVersionUID");
                returnedSkipSet.add("isDelete");
                returnedSkipSet.add("java.lang.Class");
            }
        }
    }

    /**
     * 指定类型字段跳过解析
     * @param fieldDoc
     * @return
     */
    public Boolean isFieldSkip(FieldDoc fieldDoc, Boolean isRequestParam){
        String classType = fieldDoc.qualifiedName();
        String fieldName = fieldDoc.name();
        if(isRequestParam){
            return paramSkipSet.contains(classType) || paramSkipSet.contains(fieldName);
        }
        return returnedSkipSet.contains(classType) || returnedSkipSet.contains(fieldName);
    }


}
